{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import spacy "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Run below command, if you are getting error\n",
    "# python -m spacy download en\n",
    "nlp = spacy.load(\"en\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "william_wikidef = \"\"\"William was the son of King William II and Anna Pavlovna of Russia. On the abdication of his grandfather  William I in 1840, he became the Prince of Orange. On the death of his father in 1849, he succeeded as king of the Netherlands. William married his cousin Sophie of Württemberg in 1839 and they had three sons, William, Maurice, and Alexander, all of whom predeceased him. \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(William, 'PERSON', 378), (William II, 'PERSON', 378), (Anna Pavlovna, 'PERSON', 378), (Russia, 'GPE', 382), (\n",
      ", 'GPE', 382), (William, 'PERSON', 378), (1840, 'DATE', 388), (the Prince of Orange, 'LOC', 383), (1849, 'DATE', 388), (Netherlands, 'GPE', 382), (\n",
      ", 'GPE', 382), (William, 'PERSON', 378), (Sophie, 'GPE', 382), (Württemberg, 'PERSON', 378), (1839, 'DATE', 388), (three, 'CARDINAL', 394), (William, 'PERSON', 378), (Maurice, 'PERSON', 378), (Alexander, 'GPE', 382), (\n",
      ", 'GPE', 382)]\n"
     ]
    }
   ],
   "source": [
    "nlp_william = nlp(william_wikidef)\n",
    "\n",
    "print([ (i, i.label_, i.label) for i in nlp_william.ents])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The book\n",
      "The book\n",
      "---\n",
      "nsubj\n",
      "---\n",
      "deals\n",
      "NLP\n",
      "NLP\n",
      "---\n",
      "pobj\n",
      "---\n",
      "with\n"
     ]
    }
   ],
   "source": [
    "# Noun Phrase extraction\n",
    "\n",
    "senten_ = nlp('The book deals with NLP') \n",
    "for noun_ in senten_.noun_chunks:\n",
    "    print(noun_)\n",
    "    print(noun_.text)\n",
    "    print('---')\n",
    "    print(noun_.root.dep_)\n",
    "    print('---')\n",
    "    print(noun_.root.head.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
